package com.yy.service.impl;

import com.yy.bean.Employee;
import com.yy.bean.EmployeeExample;
import com.yy.dao.EmployeeMapper;
import com.yy.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public List<Employee> getAllEmps() {
        System.out.println("====service=====");
        List<Employee> employeeList = employeeMapper.selectByExample(null);
        employeeList.forEach(System.out::println);
        return employeeList;
    }

    //根据条件查询
    public List<Employee> getEmpsByEmail(String email) {
        //employeeExample 封装查询条件
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        //and email="asda@QQ.com"
        email = "asda@QQ.com";
        criteria.andEmailEqualTo(email);
        List<Employee> employeeList = employeeMapper.selectByExample(employeeExample);
        employeeList.forEach(System.out::println);
        return null;
    }

    @Override
    public List<Employee> getEmpsByName(String empName) {
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        return employeeMapper.selectByExample(employeeExample);
    }

    @Override
    public int deleteEmpById(Integer empId) {
        return employeeMapper.deleteByPrimaryKey(empId);
    }

    @Override
    public int updateEmpById(Employee employee) {
        return employeeMapper.updateByPrimaryKey(employee);
    }

    @Override
    public int addEmp(Employee employee) {
        System.out.println("汪云飞，这里为什么不进来");
        int i = employeeMapper.insertSelective(employee);
        System.out.println("i = " + i);

        return  i;

    }
}
